package com.mashibing.service;

import com.mashibing.remote.PassengerUserRemote;
import com.mashibing.dto.ResponseResult;
import com.mashibing.dto.TokenResult;
import com.mashibing.request.VerificationCodeRequest;
import com.mashibing.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private PassengerUserRemote passengerUserRemote;

    /**
     * 通过token中的手机号查找用户信息
     * 1、解析token 获取手机号
     * 2、用手机号查询用户信息
     * @param accessToken
     * @return
     */
    public  ResponseResult getUserInfo(String accessToken){
        // 1、解析token 获取手机号
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        String phone = tokenResult.getPhone();

        // 根据手机号查询用户信息  调用service-passenger-user服务
        ResponseResult userInfoResult = passengerUserRemote.getUser(phone);

        return ResponseResult.success(userInfoResult.getData());
    }
}
